<?php
require_once ($config['basedir'] . "/include/smarty/libs/Smarty.class.php");
require_once ($config['basedir'] . "/include/classes/mysmarty.class.php");
require_once ($config['basedir'] . "/include/phpmailer/class.phpmailer.php");


global $db;


$menuArr	=	array();

function accessDenied()
{
	stemplate::display("admin/no_auth.tpl");
	exit;	
}

$sql = "SELECT * FROM settings";
$rows = $db->get("settings");	
foreach($rows as $tmp)
{
    $field = $tmp['soption'];
    $config[$field] = $tmp['svalue'];
    stemplate::assign($field, $config[$field]);
}

if( count($GLOBALS) > 0 )
{
	foreach($GLOBALS as $key=>$value)
	{
		stemplate::assign($key, $value);
	}
}

if(isset($_COOKIE['theme'])){
    $config['theme'] = $_COOKIE['theme'];
}

$config['official_types'] = array( 1 => "Umpire" , 2 => "Scorer", 3=> "Referee");

$banner_postion_array = array("bottom center"=>'bottom center',"right"=>'right',"right center"=>'right center',"right bottom"=>'right bottom',"top center"=>'top center', 'top bottom'=> 'top bottom');
$config['page_limit'] = 10;

// photo gallery configuration 

$config['photo_gallery_tag_lookup_page_limit'] = 40;
$config['photo_gallery_image_max_width'] = 1024;
$config['photo_gallery_thumb_max_width'] = 100;

// END photo gallery configuration 


$config['imgurl'] = $config['baseurl'] . "/templates/frontend/".$config['theme']."/images";
$config['cssurl'] = $config['baseurl'] . "/templates/frontend/".$config['theme']."/css";

$config['admin_imgurl'] = $config['baseurl'] . "/templates/admin/images";
$config['admin_cssurl'] = $config['baseurl'] . "/templates/admin/css";

stemplate::assign("baseurl", $config['baseurl']);
stemplate::assign("basedir", $config['basedir']);
stemplate::assign("imgurl", $config['imgurl']);
stemplate::assign("cssurl", $config['cssurl']);
stemplate::assign("banner_postion_array", $banner_postion_array);

stemplate::assign("admin_imgurl", $config['admin_imgurl']);
stemplate::assign("admin_cssurl", $config['admin_cssurl']);

stemplate::assign("template_dir", $config['baseurl'] . "/templates/frontend/".$config['theme']."");
stemplate::setcompiledir($config['basedir'] . "/templates_c");
stemplate::settpldir($config['basedir'] . "/templates");



stemplate::assign("session", $_SESSION);

if(isset($_SESSION['admin_id']) && $_SESSION['admin_id'] != '')
{
	stemplate::assign("admin_login", 1);
}






//echo $_SERVER['QUERY_STRING'];
function getParentCategoriesItems($categoryID){
	global $db,$menuArr;
	//$menuArr	=	array();
	
	$sql_ = "select * from photo_category where category_id='".$categoryID."' ";
	$row = $db->first($sql_);	
	if(count($row)>0){			
		$menuArr[] = array($row['category_name'],$row['category_id']);
		if($row['parent_id']>0)
			getParentCategoriesItems($row['parent_id']);
	}
	return array_reverse($menuArr);
}

function getParentMenuItems($menuSEOURL){
	global $db,$menuArr;
	$sql_ = "select * from menus where url like '".$menuSEOURL."' ";
	$row = $db->first($sql_);	
	if(count($row)>0){
		if($row['article_type']=='article')
			$row['url'] = $row['url'].'.html';
			
		$menuArr[] = array($row['menu_name'],$row['url'],$row['article_type']);
		if($row['parent_menu']>0)
			getParentMenuItems(getParentMenuURL($row['parent_menu']));
	}
	return array_reverse($menuArr);
}
function getParentMenuURL($menuID){
	global $db;
	$sql_ = "select * from menus where menu_id=".$menuID;
	$row = $db->first($sql_);	
	return $row['url'];
}

	
	function redirect($location)
	{
		global $config;
		$location = $config['baseurl']."/".$location;
		
		if (!headers_sent())
			header('Location: '.$location);
		else {
			echo '<script type="text/javascript">';
			echo 'window.location.href="'.$location.'";';
			echo '</script>';
			echo '<noscript>';
			echo '<meta http-equiv="refresh" content="0;url='.$location.'" />';
			echo '</noscript>';
		}
	}	
	
	$showMsg = '';
	
	function toDbFormat($date)
	{
		$parts = @explode('-', $date);
		$date = array_reverse($parts);
		$date = implode('-', $date);
		return $date;
	}


// =============================================================

  function redirect_to($location) {
	  
    if (!headers_sent())
        header('Location: '.$location);
    else {
        echo '<script type="text/javascript">';
        echo 'window.location.href="'.$location.'";';
        echo '</script>';
        echo '<noscript>';
        echo '<meta http-equiv="refresh" content="0;url='.$location.'" />';
        echo '</noscript>';
    }
  }

  /**
   * display_msg()
   * 
   * @return
   */
  function display_msg()
  {
      global $msgOk, $msgError, $msgAlert, $msgInfo, $msgSys, $showMsg;
      
      if (!empty($msgOk)) {
          return "<div id=\"fader\"><div class=\"success\">" . $msgOk . "</div></div>
    <script type=\"text/javascript\"> 
    // <![CDATA[
    jQuery(document).ready(function() {       
      setTimeout(function() {       
        jQuery(\"#fader\").customFadeOut(\"slow\" ,    
        function() {       
          jQuery(\"#fader\").remove();  
        });
      },
      4000);
    });
    // ]]>
    </script>";
      }
      if (!empty($msgError)) {
          return "<div id=\"fader\"><div class=\"error\">" . $msgError . "</div></div>
    <script type=\"text/javascript\"> 
    // <![CDATA[
    jQuery(document).ready(function() {       
      setTimeout(function() {       
        jQuery(\"#fader\").customFadeOut(\"slow\",    
        function() {       
          jQuery(\"#fader\").remove();  
        });
      },
      4000);
    });
    // ]]>
    </script>";
      }
      if (!empty($msgAlert)) {
          return "<div id=\"fader\"><div class=\"msgAlert\">" . $msgAlert . "</div></div>
    <script type=\"text/javascript\"> 
    // <![CDATA[
    jQuery(document).ready(function() {       
      setTimeout(function() {       
        jQuery(\"#fader\").customFadeOut(\"slow\",    
        function() {       
          jQuery(\"#fader\").remove();  
        });
      },
      4000);
    });
    // ]]>
    </script>";
      }
      if (!empty($msgInfo)) {
          return "<div id=\"fader\"><div class=\"msgInfo\">" . $msgInfo . "</div></div>
    <script type=\"text/javascript\"> 
    // <![CDATA[
    jQuery(document).ready(function() {       
      setTimeout(function() {       
        jQuery(\"#fader\").customFadeOut(\"slow\",    
        function() {       
          jQuery(\"#fader\").remove();  
        });
      },
      4000);
    });
    // ]]>
    </script>";
      }
      return $showMsg;
  }
  
  function isvalidemail($email) {
		  $result = TRUE;
		  if(!preg_match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email)) {
			$result = FALSE;
         }
 		 return $result;
 }//end function

 	function trim_array(&$data)
	{
		if (is_array($data))
		{
			foreach ($data as $key => $val)
			{
				if(!is_array($val))
				$data[$key] = trim($val);		
			}
		}
	}
	function sendEmail($to, $subject, $message, $from_name = 'Admin', $from_email='info@tfntech.com')
	{   
		  
		   
		    $mail             = new PHPMailer();
			$body             = $message;
			$mail->IsSMTP(); // telling the class to use SMTP
			$mail->Host       = "mail.tfntech.com"; // SMTP server
			$mail->From       = $from_email;
			$mail->FromName   = $from_name;
			$mail->Subject    = $subject;
			$mail->MsgHTML($body);
			$mail->AddAddress($to,'');
		  
			if(!$mail->Send()) {
				return false;
			} else {
				return true;
			}
			
			
	      
	}
	# This function remove special charach
	function removeSpecialChar($string)
	{
		$string=strtolower($string);
		$code_entities_match = array(' ','--','&quot;','!','@','#','$','%','^','&','*','(',')','_','+','{','}','|',':','"','<','>','?','[',']','\\',';',"'",',','.','/','*','+','~','`','=');
		$code_entities_replace = array(' ',' ','','','','','','','','','','','','','','','','','','','','','','','','');
		$string = str_replace($code_entities_match, $code_entities_replace, $string);
		return $string;
	}
	
	
	
	function cleanSpecialCharHTML($string)
	{
		$string = strip_tags($string);
		$string = removeSpecialChar($string);
		return $string;
	}
	
	function clean_array(&$data, $key_skip = '')
	{
		if (is_array($data))
		{
			foreach ($data as $key => $val)
			{
				if(!is_array($val))
				{
					if( $key_skip != '')
					{					
						if( is_array($key_skip) )
						{
							if( !empty($val) && !in_array($key_skip, $key) )
							{
								
								$data[$key] = strip_tags($val);		
							}
						}
						else
						{
							if( !empty($val) && $key_skip != $key)
							{
								$data[$key] = strip_tags($val);		
							}
						}		
					}	
					else
					{
						$data[$key] = strip_tags($val);
					}
				}	
			}
		}
	}
	
	function isAlphabetOnly($string)
	{
		if(preg_match("/^[a-zA-Z ]+$/",$string))
		{
			return TRUE;
		}
		else
		{
			return FALSE;
		}
	}
	
	function varDump($data)
	{
		echo "<pre>";	
		print_r($data);
	    echo "</pre>";
	}
	
	//function x permissions
	function chk_permission($module_short_name,$permission=false){
             global $db; 
			 $user_id = $_SESSION['admin_id'];
			// echo '*******************'.$user_id;exit;
			 $group_id = intval($_SESSION['group_id']);
			 $is_admin = $_SESSION['is_admin'];
			  
			 
			 if($is_admin == '1')
			 { 
			 	return TRUE; 
			 }
			 elseif($module_short_name == 'user_groups' OR $module_short_name == 'users')
			 {
			 	 stemplate::display("admin/no_auth.tpl");
	 			 exit;
			 }
 		     $sql = "     select permission,modules.module_short_name 
					 	  from module_permission , module_category , modules
  						  where module_permission.module_category_id  =   module_category.module_category_id
						  and modules.module_category_id =  module_category.module_category_id
						  and FIND_IN_SET('view',permission) AND modules.module_short_name = '".$module_short_name."'
						  and module_permission.group_id = '".$user_id."'";
			$data_permission = $db->first($sql);
			if(sizeof($data_permission)>0){  
			 	  $list =  split(",",$data_permission['permission']);
			      if(in_array($permission,$list)){
					 return true;
				 }else{
				      stemplate::display("admin/no_auth.tpl");  
					  exit;
				 }
		     }else{
					  $group_permissio_qry = " select permission,modules.module_short_name 
					  from module_permission , module_category , modules
					  where module_permission.module_category_id  =   module_category.module_category_id
					  and modules.module_category_id =  module_category.module_category_id
					  and FIND_IN_SET('".$permission."',permission) AND modules.module_short_name = '".$module_short_name."'
					  and module_permission.group_id = '".$group_id."'";
					 $group_permission_data = $db->first($group_permissio_qry);
			   if(sizeof($group_permission_data)>0){ 
			      return true;
			       
			   }else{
			   		stemplate::display("admin/no_auth.tpl"); 
					exit;
			  }
		    }//end if sizeof 	   
  }//end function chk_permission
	
  

	
	function replicateDataInBody($body,$data_keys )
	{
		foreach($data_keys as $key=>$value)
		{
			$body = str_replace($key, $value, $body);
		}		
		return $body;
	}  
	function isValidUserName($username)
	{
	  if(preg_match("/^[a-zA-Z0-9\.]+$/",$username))
	  {
	   return TRUE;
	  }
	  else
	  {
	   return FALSE;
	  }
	}
  
	
	
	function  insert_getTopBottom()
	{    
		bannerRotation('top_bottom');
	}
	
	function  insert_getRightCenter()
	{    
		bannerRotation('right_center');
	}
	
	function  insert_getRightBottom()
	{    
		bannerRotation('right_bottom');
	}
	
	
	function  insert_getBottomBanner()
	{
	  	bannerRotation('bottom_center');
	}
	function  insert_getTopCenter()
	{
	  	multipleBannerRotation('top_center');
	}
	
	function getPositionIdByName($position_name)
	{
		global $db;
		$sql="select position_id from banner_position where position_name = '$position_name'";
		$row =$db->first($sql);
		return $row['position_id'];	
	}
	
	
	function bannerRotation($banner_position)
	{
		
	   $banner_position = getPositionIdByName($banner_position);
		
	   global $db,$config;
	   $dest=$config['baseurl']."/images/banners";
 	   $sql="select * from banners as b  INNER JOIN banner_size bs ON b.banner_size_id = bs.size_id
	           where   b.rotatestatus!=1 AND b.banner_position ='$banner_position'  
			   order by rand() limit 1";
 	   
	    $row = $db->first($sql);
		
		if(intval($row[banner_id]) < 1)
			return '';

 	    $id=$row['banner_id'];
		$banner_size=$row['banner_size'];
		$size_arr = explode('x',$banner_size);
		$width = $size_arr[0];
		$height = $size_arr[1];
		$link=trim($row['banner_link']);
		$rotatestatus=$row['rotatestatus'];
		$content=$row['content'];
		$type=$row['banner_type'];
		
		
		if($type=="image")	
		{  
		    if($link!=""){
					    $link = str_replace("http://","",$link);
					
			}
			if( file_exists($config['basedir']."/images/banners/".$row['banner_image'])){
				
				if($link!="")
				{
					echo "<a href='http://".$link."' target='_blank'><img src=".$dest."/".$row['banner_image']." width ='".$width."' height = '".$height."'></a>";
				}
				else
				{
					echo "<img src=".$dest."/".$row['banner_image']." width ='".$width."' height = '".$height."'>";
				}
				
			
		    }
		 }
		else
		{
			echo '<div style="overflow:hidden;height:'.$height.'px; width:'.$width.'px;"> '.$row['banner_code'].' </div>';
		}

		//echo '</div>';
	


		/*echo "id:".$id."<br>";
		echo "rotation:".$row['rotatetime']."<br>";
		echo "fr : ".getFrequency($id)."<br>";*/
		
		
		
		$rotatetime=$row['rotatetime'];
		
		//echo getFrequency($id)." != $rotatetime";
		
		if(getFrequency($id) != $rotatetime)
		{ 
 			global $db;
			$q="update banners set rotatetime=(rotatetime+1) where banner_id=$id";
			$res=$db->query($q);
		 }
		 
		 //echo "<br>".getBannerRotation($id);
		// echo "<br>".getFrequency($id);
		 
		 
		 
		  if(getFrequency($id)==getBannerRotation($id)){
		     global $db;
			 $q="update banners set rotatestatus=1 where banner_id=$id";
			$res=$db->query($q);
		  }
		 
		// exit;
		  
		 // $type = 'right center';
		  
		  if(getBannerStatus($banner_position)==0)
		  { global $db;
		  	$qu="update banners set rotatestatus=0 where banner_position = '$banner_position' ";
			$res=$db->query($qu);
			$query="update banners set rotatetime=0 where banner_position = '$banner_position' ";
			$re=$db->query($query);
		   }
		  
 		 
			
	
	}
	
	function multipleBannerRotation($banner_position)
	{
		 $banner_position = getPositionIdByName($banner_position);
	
	   global $db,$config;
	  $dest=$config['baseurl']."/images/banners";
	   
 	   $limit_clause = 3 ; 
 	   $sql="select * from banners as b  INNER JOIN banner_size bs ON b.banner_size_id = bs.size_id
	         where b.rotatestatus!=1 AND b.banner_position ='$banner_position'  
		     order by b.banner_order limit $limit_clause";
 	   $result = $db->fetch_all($sql);
	    if(sizeof($result)< 1)
			return '';
         foreach($result as $row){	
		 
				$id	= $row['banner_id'];
				$banner_size = $row['banner_size'];
				$size_arr = explode('x',$banner_size);
				$width = $size_arr[0];
				$height = $size_arr[1];
				$link=trim($row['banner_link']);
				$rotatestatus=$row['rotatestatus'];
				$content=$row['content'];
				$type=$row['banner_type'];
				
				if($type=="image"){  
					if($link!=""){
					    $link = str_replace("http://","",$link);
					
					}
					
					if( file_exists($config['basedir']."/images/banners/".$row['banner_image'] ))
					{
						if($link!="")
						{
							echo "<a href='http://".$link."' target='_blank'><img src=".$dest."/".$row['banner_image']." width ='".$width."' height = '".$height."'></a>";
						}
						else
						{
							echo "<img src=".$dest."/".$row['banner_image']." width ='".$width."' height = '".$height."'>";
						}
			        }
					}else{
					echo '<div style="overflow:hidden;height:'.$height.'px; width:'.$width.'px;"> '.$row['banner_code'].' </div>';
				   }
		
				  $rotatetime=$row['rotatetime'];
		
				//echo getFrequency($id)." != $rotatetime";
		
				if(getFrequency($id) != $rotatetime){ 
					global $db;
					$q="update banners set rotatetime=(rotatetime+1) where banner_id=$id";
					$res=$db->query($q);
				 }
		 
		 //echo "<br>".getBannerRotation($id);
		// echo "<br>".getFrequency($id);
		 
		 
		 
				  if(getFrequency($id)==getBannerRotation($id)){
					 global $db;
					 $q="update banners set rotatestatus=1 where banner_id=$id";
					 $res=$db->query($q);
				  }
		 
				  if(getBannerStatus($banner_position)==0){ 
						global $db;
						$qu="update banners set rotatestatus=0 where banner_position = '$banner_position' ";
						$res=$db->query($qu);
						$query="update banners set rotatetime=0 where banner_position = '$banner_position' ";
						$re=$db->query($query);
				 }
  		}//endforeach   
	
		$completed_freq_banner = getCompletedFrequencyBanner($banner_position,$limit_clause);
		if($completed_freq_banner <= 3 ){
				$qu="update banners set rotatestatus=0 where banner_position = '$banner_position' and rotatestatus=1 ";
				$db->query($qu);
		} 
}//end function multipleBannerTotation
	

function getCompletedFrequencyBanner($banner_position , $limit_clause){
	
		global $db;
		$sql="select * from banners where banner_position = '$banner_position' and rotatestatus = 1 
			  order by rotatestatus desc limit $limit_clause ";
 		$res = $db->query($sql);
		$num_rows = $db->num_rows($res );
		return $num_rows;

}	
	  

//----------------------------------
function getFrequency($bid){ 
		global $db;
		$sql="select banner_set_frequency from banners where banner_id = $bid and status=1";
		$row =$db->first($sql);
		return $row['banner_set_frequency'];
	 }
	 
	 function getBannerRotation($bid)
	 {      global $db;   
			$sql="select rotatetime from banners where banner_id=$bid and status=1";
			$row=$db->first($sql);
			return $row['rotatetime'];
     }
	 
	 
	 function getBannerStatus($type = '')
	{ 
			global $db;
			
			$AND = '';
			
			if($type != '')
			{
				$AND = " AND banner_position = '$type' ";
			}
						
			$sql="select count(banner_id) as bIds from  banners where rotatestatus=0 and status=1 $AND ";
			$row =$db->first($sql);
			return $row['bIds'];
 	}
	//--------------------------
	//=========================End Image Rotaion========= 
	
	// funciton make javascript variables, function takes the array of name, with name get the $GLOBAL messages and set them in javascript variables
	
	function makeJavaScriptVarForMessages($global_var_names)
	{
		$var_string = "<script>";
		foreach($global_var_names as $key)
		{
			$key = strtoupper($key);
			$var_string .= "$key = '".addslashes($GLOBALS[$key])."';";
		}
		$var_string .= "</script>";
		return $var_string;
	}

//-----------------------------------------

	 function getCountryList()
	 {       			  
		global $db;	
		$sql = "SELECT * FROM pcb_country order by country_id";
		$disttricts = $db->fetch_all($sql);
		return $disttricts;
	 }
	 
	function getTournamentTypes()
	{
		global $db;
		$sql = "select * from pcb_tournament_type";
		return $db->fetch_all($sql);
	}
	
	function getMatchTypes($tournament_type_id)
	{
		global $db;
		$tournament_type_id = intval($tournament_type_id);
		$sql = "select * from pcb_match_type where tournament_type_id = $tournament_type_id";
		return $db->fetch_all($sql);
	}
	
	function getCountries()
	{
		global $db;
		$sql = "select * from pcb_country";
		return $db->fetch_all($sql);
	}
	
	function getTournaments()
	{
		global $db; 
		$data = $db->fetch_all("SELECT * FROM pcb_tournament ");
		return $data;
	}
	
	function getSeasons()
	{
			$start = 2000;
			$current_year = date('Y')+1;
			$season_array = array();
			for($year = $start; $year <= $current_year; $year++)
			{
			$season_array[] = $year;
			if( $year < $current_year )
			$season_array[] = $year."/".substr($year+1, 2 );
			}
			
			return $season_array;
	}
	
	function getPlayerRoles()
	{
		global $db;
		$sql = "select * from pcb_player_role ";
		return $db->fetch_all($sql);	
	}
	
	function getTableName($match_type , $table){
		
		if($match_type == "TEST"){
			
				if($table == "batting"){
					
					return 'pcb_match_test_batting';	
					
				}elseif($table == "bowling"){
					
					return 'pcb_match_test_bowling';	
					
				}elseif($table == "commentary"){
					
					return 'pcb_match_test_commentary';	
				}
		}elseif($match_type == "ODI"){
			
				if($table == "batting"){
					
					return 'pcb_match_odi_batting';	
					
				}elseif($table == "bowling"){
					
					return 'pcb_match_odi_bowling';	
					
				}elseif($table == "commentary"){
					
					return 'pcb_match_odi_commentary';	
				}
		}elseif($match_type == "T20"){

				if($table == "batting"){
					
					return 'pcb_match_t20_batting';	
					
				}elseif($table == "bowling"){
					
					return 'pcb_match_t20_bowling';	
					
				}elseif($table == "commentary"){
					
					return 'pcb_match_t20_commentary';	
				}

		}
		
	}//function end 
	//###########################Following function is used for show menus on home page##########################
	function getChildCount($id){
	    global $db;
		$sql = 'SELECT * FROM menus WHERE parent_menu ="'.$id.'"';
		$result = $db->query( $sql );
		  $db->num_rows($result); 
		return $db->num_rows($result); 
	}//=============
   
 	function isChildMenu($id)
	{
	    global $db;
		$sql = 'SELECT * FROM menus WHERE parent_menu > 0 AND menu_id ="'.intval($id).'"';
		$rs =  $db->query( $sql );
		if($db->num_rows($rs) > 0)
		{
			$data = $db->first($rs);
			return $data['parent_menu'];
		} 
		return 0;
	}//=============
 
    // insert_getChildMenu(0);
	function insert_getChildMenu($param){
		
			if(is_array($param)){
				$menu_id = $param['menu_id'];
			} else {
				$menu_id = $param;
			}
			
			
			global $db , $config; 
	
 		  $sql_ = 'SELECT *  
					 FROM menus WHERE parent_menu ="'.$menu_id.'" ORDER BY menu_ordering';
			
			 $res = $db->fetch_all( $sql_ );
			 $html.='<ul>'; 
			 
			//print_r($res);exit;
			 
 			 foreach($res as $row){
			 		
						
						if( $row['content_id'] == 0 ) 
						{
							$link = $config['baseurl'].'/'.$row['url'];
						} 
						else 
						{
							$row['url'] = removeSpecialCharURLs($row['url']);
							$link = $config['baseurl'].'/contents/'.$row['url'].".html";
						}
						
						if ( strtolower($row['menu_name']) == 'home') 
						{
							$link = $config['baseurl'];
						}
						
						/*if( strtolower($row->menu_name) == 'domestic cricket') 
						{
							$link = $site_url.'content/domestic-cricket-calendar-41.html'; 
						}
						
						
						if( strtolower($row->menu_name) == 'cricket news') 
						{
							$link = $site_url.'news.html';
						}
						*/
						
						

			 		   $total_child =  getChildCount($row['menu_id']);
			           $menu_name  =  $row['menu_name'];
					   if($total_child  > 0 ){
						   $span = '<span class=\'ddarrow\'></span>';
					   }else{
						   $span = '';    
					   }
			   		   $html.="<li><a ".$class." href='{$link}'>".$menu_name."</a>".$span.""; 				
						 if($total_child  > 0 ){ 
								 $html.=insert_getChildMenu( $row['menu_id'] );	
						 }
					   $html.="</li>";
			 }
			 $html.='</ul>'; 
			 return $html;
 	}//=============
	
	function removeSpecialCharURLs($string)
	{
	 	$array = array(" ","/",".","`","&",",","=","^","$","@","!","?","~","#",":","+","++");
	 	$first_replace = trim(str_replace($array,"-",(trim($string))));
	 	$special_char= array("----","---","--","-");
	 	return strtolower(str_replace($special_char,"-",$first_replace));
	}
	
	
   //========================================= END Menus Functions ===============================================	
	
	function getInternationalTeams()
	{
		global $db;
		$sql = "select * from pcb_teams where tournament_type_id = 1	";
		return $db->fetch_all($sql);	
	}
	
	
	function getEndingInningStatusByMatchType($match_type){
		
		if($match_type == "TEST"){
			$array = array(1=>"Over Completed" ,2=>"ALL Out",3=>"Inning Declared",4=>"Time End" );
		}elseif($match_type == "ODI"){
			$array = array(1=>"Over Completed" ,2=>"ALL Out"  );
		}elseif($match_type == "T20"){
			$array = array(1=>"Over Completed" ,2=>"ALL Out" );
		}
		
		return $array ;
 	}


	function getMatchStatusByMatchType($match_type){
		
		if($match_type == "TEST"){
			$array = array("Progress"=>"Progress" ,"Tea Break"=>"Tea Break","Lunch Break"=>"Lunch Break","Drinks Break"=>"Drinks Break","Stumps"=>"Stumps" , "Innings Break"=>"Innings Break", "Match stopped due to rain"=>"Match stopped due to rain" , "Start delayed due to rain" => "Start delayed due to rain" , "Bad Light stopped play" =>"Bad Light stopped play" , "Start delayed due to Bad Light" => "Start delayed due to Bad Light" , "Start delayed due to wet outfield" => "Start delayed due to wet outfield");
		}elseif($match_type == "ODI"){
			$array = array("Progress"=>"Progress" ,"Tea Break"=>"Tea Break","Lunch Break"=>"Lunch Break","Drinks Break"=>"Drinks Break", "Innings Break"=>"Innings Break", "Match stopped due to rain"=>"Match stopped due to rain" , "Start delayed due to rain" => "Start delayed due to rain" , "Bad Light stopped play" =>"Bad Light stopped play" , "Start delayed due to Bad Light" => "Start delayed due to Bad Light" , "Start delayed due to wet outfield" => "Start delayed due to wet outfield");
		}elseif($match_type == "T20"){
			$array = array("Progress"=>"Progress" ,"Tea Break"=>"Tea Break","Lunch Break"=>"Lunch Break","Drinks Break"=>"Drinks Break", "Innings Break"=>"Innings Break", "Match stopped due to rain"=>"Match stopped due to rain" , "Start delayed due to rain" => "Start delayed due to rain" , "Bad Light stopped play" =>"Bad Light stopped play" , "Start delayed due to Bad Light" => "Start delayed due to Bad Light" , "Start delayed due to wet outfield" => "Start delayed due to wet outfield");
		}
		
		return $array ;
 	}
	
	function getMatchResultByMatchType($match_type){
		
		if($match_type == "TEST"){
			$array = array("draw"=>"Draw" ,"tie"=>"Tie","match_win"=>"Win and loss","abandoned"=>"Abandoned","awarded"=>"Awarded" );
		}elseif($match_type == "ODI"){
			$array = array("tie"=>"Tie","match_win"=>"Win and loss","no_result"=>"No result","abandoned"=>"Abandoned","awarded"=>"Awarded" );
		}elseif($match_type == "T20"){
			$array = array("tie"=>"Tie","match_win"=>"Win and loss","no_result"=>"No result","abandoned"=>"Abandoned","awarded"=>"Awarded" );
		}
		
		return $array ;
 	}
  //following associatvie array use for filter the stats record
  $home_or_away_array = array("home_venue"=>'Home Venue',"away_home_or_of_opposition "=>'Away Home OR Of Opposition',"neutral_venue"=>'Neutral Venue');	
  
  
  $match_types_one_day_or_t20 = array(
  										"tournament_finals "=>'Tournament Finals',
										"tournament_quarter_finals "=>'Tournament Quarter Finals',
										"tournament_semi_finals"=>'Tournament Semi Finals',
										"preliminary_quarter_finals "=>'Preliminary Quarter Finals',
										"preliminary_matches"=>'Preliminary Matches',
										"day_night_match "=>'Day Night Match',
										"day_match"=>'Day Match',"either"=>'Either'
					   				  );
 $day_night_or_day = array("day_night_match "=>'Day Night Match',"day_match"=>'Day Match',"either"=>'Either');									  
 $match_types_test = array("tournament finals "=>'Tournament Finals',"preliminary matches"=>'Preliminary Matches');	 	
	
	
// code added by mohsin //
	
$config['dismissal_ids'] = array(1,2,3,4,5,6,7,10,11,12,13,14,15,16,17); // dismissal type for which batsman consider to be out
$config['non_dismissal_ids'] = array(8,9);	// dismissal type for which batsman consider to be out


	
	// end code added by mohsin //
	
 //=============================================
function parseXMLFileTOString($Url){
	 
		 if (!function_exists('curl_init')){
			die('Sorry cURL is not installed!');
		}
		 $ch = curl_init();
		 curl_setopt($ch, CURLOPT_URL, $Url);
		 curl_setopt($ch, CURLOPT_REFERER, "http://www.example.org/yay.htm");
		 curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
		 curl_setopt($ch, CURLOPT_HEADER, 0);
		 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		 curl_setopt($ch, CURLOPT_TIMEOUT, 10);
		 $output = curl_exec($ch);
		 curl_close($ch);
		return $output;
}//function 


function core_categories(){
		global $db;
		$sql = "select * from category where status = 1 and parent_id = 0 ";
		$result = $db->fetch_all($sql);
 		return $result ; 
}//function 
?>